package com.erp.base.business.service;

import java.util.Date;
import java.util.List;

import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.stereotype.Service;

import com.erp.base.base.CrudService;
import com.erp.base.business.dao.ProvincialDao;
import com.erp.base.business.entity.Provincial;
import com.erp.base.common.utils.ShiroUtils;
import com.erp.base.system.entity.User;

@Service
public class ProvincialService extends CrudService<ProvincialDao, Provincial, Long> {
	@Override
	public void save(Provincial provincial) {
		User user=ShiroUtils.getUser();
		if (provincial.getIsNewRecord()){ 
			provincial.setCreateBy(user.getName());
			provincial.setCreateDate(new Date());
			provincial.setUpdateBy(user.getName());
			provincial.setUpdateDate(new Date());
			dao.insert(provincial);
		}else{
			provincial.setUpdateBy(user.getName());
			provincial.setUpdateDate(new Date());
			int i=dao.update(provincial);
			if(i==0){
				throw new OptimisticLockingFailureException("乐观锁错误!") ;
			}
		}
	}
	
	public List<Provincial> getAllProv(){
		return dao.findList(new Provincial());
	}
}
